package edu.upc.galaxy.dao;

import edu.upc.galaxy.entity.CanchaENTITY;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alvaro
 */
public class CanchaDAO extends BaseDAO {
    

    
    public Integer insertar(CanchaENTITY cancha) {
        String insert = "insert into cancha(nombre,caracteristica) values (?,?)";
        List list = new ArrayList();
        list.add(cancha.getNombre());
        list.add(cancha.getCaracteristica());
        return this.insert(insert, list);
    }
    
    public void actualizar(CanchaENTITY cancha) {
        String update = "update cancha set nombre = ?, caracteristica = ? where id = ?";
        List list = new ArrayList();
        list.add(cancha.getNombre());
        list.add(cancha.getCaracteristica());
        list.add(cancha.getCodcancha());
        this.update(update, list);
    }
    
    public void eliminar(CanchaENTITY cancha) {
        String delete = "delete from cancha where id = ?";
        this.delete(delete,cancha.getCodcancha());
    }
    
    public List<CanchaENTITY> buscar() {
        ResultSet rs = this.select("select * from cancha");
        List<CanchaENTITY> listado = new ArrayList<CanchaENTITY>();
        try {
            while (rs.next()) {
                CanchaENTITY cancha = new CanchaENTITY();
                cancha.setCodcancha(rs.getInt(1));
                cancha.setNombre(rs.getString(2));
                cancha.setCaracteristica(rs.getString(3));
                listado.add(cancha);
            }
        } catch (SQLException ex) {
            Logger.getLogger(CanchaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listado;
        
        
    }  
   public List<CanchaENTITY> mostrarCancha() throws Exception{
    	ResultSet rs = this.select("select * from cancha");
        List<CanchaENTITY> listado = new ArrayList<CanchaENTITY>();
		try{
    		  //new conecta();
 		//	  cn = conecta.obtenerConexion();
    	      //cs = cn.prepareCall("{call usp_listar_canchas()}");
    	      //rs = cs.executeQuery();
    	      //lista = new ArrayList<cancha>();
    	       while(rs.next()){
    	    	   CanchaENTITY cancha = new CanchaENTITY();
    	    	   cancha.setCodcancha(Integer.parseInt(rs.getString(1)));
    	    	   cancha.setNombre(rs.getString(2));
    	    	   cancha.setCaracteristica(rs.getString(3));
    	    	   //cancha.setDias_atencion(rs.getString(4));
    	  //  	   cancha.setTarifa(rs.getString(4));
    	    	   cancha.setPromocion(rs.getString(6));
    	  //  	   cancha.setLocal(rs.getString(7));
 	//    	   cancha.setTelefono(rs.getString(8));
    	           listado.add(cancha);
    	           }
    	       rs.close();
    	   //    cs.close();
    	     //  cn.close();
    	}catch (SQLException e) {
       	 e.printStackTrace();
        }
    	
    	return listado;
    }
 
    
}
